package org.dawning.fantasy.core.common;

import com.alibaba.fastjson.JSONObject;

/**
 * @author miou
 * Created by fyx on 2017/3/22 0022.
 */
public class BaseMQData {

    private String event;

    private String message;

    private JSONObject data;

    public BaseMQData() {
    }

    public BaseMQData(String event, String message) {
        this.event = event;
        this.message = message;
    }

    public BaseMQData(String event, String message, JSONObject data) {
        this.event = event;
        this.message = message;
        this.data = data;
    }

    public BaseMQData(String event, String message, String action,String obj) {
        this.event = event;
        this.message = message;
        this.data = createData(action,obj);
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    public JSONObject createData(String action, Object obj){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("action",action);
        jsonObject.put("obj",obj);
        data = jsonObject;
        return data;
    }

    public String findJSONAction(){
        if (data!=null){
            return data.getString("action");
        }
        return "";
    }

    public String findJSONObj(){
        if (data!=null){
            return data.getString("obj");
        }
        return "";
    }
}
